//
//  NSDate+transform.m
//  FWShare
//
//  Created by 范文青 on 14-6-14.
//  Copyright (c) 2014年 fwq. All rights reserved.
//

#import "NSDate+transform.h"

@implementation NSDate (transform)
+ (NSDate *)sinaDate:(NSString *)stringOfCreatedAt
{
    time_t createdAt ;
    struct tm created;
    time_t now;
    time(&now);
    if (stringOfCreatedAt) {
        if (strptime([stringOfCreatedAt UTF8String], "%a %b %d %H:%M:%S %z %Y", &created) == NULL) {
            strptime([stringOfCreatedAt UTF8String], "%a, %d %b %Y %H:%M:%S %z", &created);
        }
        createdAt = mktime(&created);
    }
    static NSDateFormatter *dateFormatter = nil;
    if (dateFormatter == nil) {
        dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
        [dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
    }
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:createdAt];
    return date;
}
@end
